// pages/nearby/index.js
Page({
  data: {
    users: [
      {
        id: 1,
        name: "城旅达人",
        avatar: "/assets/img/profile/profile.png",
        distance: "50m",
        age: 25,
        gender: "男",
        signature: "发现城市美好，分享生活点滴",
        tags: ["美食", "摄影", "旅行"],
        online: true
      },
      {
        id: 2,
        name: "美食推荐官",
        avatar: "/assets/img/profile/account.png",
        distance: "120m",
        age: 23,
        gender: "女",
        signature: "探索城市美食，记录美好味道",
        tags: ["美食", "探店", "分享"],
        online: true
      },
      {
        id: 3,
        name: "摄影爱好者",
        avatar: "/assets/img/profile/medal.png",
        distance: "200m",
        age: 28,
        gender: "男",
        signature: "用镜头记录城市的美",
        tags: ["摄影", "艺术", "创作"],
        online: false
      },
      {
        id: 4,
        name: "旅行者",
        avatar: "/assets/img/profile/collect.png",
        distance: "300m",
        age: 26,
        gender: "女",
        signature: "世界那么大，我想去看看",
        tags: ["旅行", "户外", "冒险"],
        online: true
      },
      {
        id: 5,
        name: "本地通",
        avatar: "/assets/img/profile/gift.png",
        distance: "500m",
        age: 30,
        gender: "男",
        signature: "最了解这座城市的人",
        tags: ["本地", "攻略", "推荐"],
        online: false
      }
    ],
    filters: [
      { name: "全部", active: true },
      { name: "在线", active: false },
      { name: "附近", active: false },
      { name: "同龄", active: false }
    ]
  },

  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '附近的人'
    })
  },

  onUserTap: function(e) {
    const user = e.currentTarget.dataset.user
    
    wx.showModal({
      title: user.name,
      content: `距离：${user.distance}\n年龄：${user.age}岁\n性别：${user.gender}\n个性签名：${user.signature}\n标签：${user.tags.join('、')}\n状态：${user.online ? '在线' : '离线'}`,
      showCancel: true,
      cancelText: '关闭',
      confirmText: '打招呼',
      success: function(res) {
        if (res.confirm) {
          wx.showToast({
            title: '打招呼功能开发中',
            icon: 'none'
          })
        }
      }
    })
  },

  onFilterTap: function(e) {
    const index = e.currentTarget.dataset.index
    const filters = this.data.filters.map((item, i) => {
      item.active = i === index
      return item
    })
    this.setData({ filters })
    
    wx.showToast({
      title: '筛选：' + filters[index].name,
      icon: 'none'
    })
  },

  onRefreshTap: function() {
    wx.showLoading({
      title: '刷新中...'
    })
    
    setTimeout(() => {
      wx.hideLoading()
      wx.showToast({
        title: '刷新成功',
        icon: 'success'
      })
    }, 1000)
  }
})
